package org.example.registermvc;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class RegisterController {

    @ModelAttribute("provinceList")
    public List<String> provinceList() {
        List<String> provinceList = new ArrayList<>();
        provinceList.add("广东省");
        provinceList.add("广西省");
        provinceList.add("上海");
        provinceList.add("北京");
        return provinceList;
    }

    @ModelAttribute("sportsMap")
    public Map<Integer, String> getSports() {
        Map<Integer, String> sportsMap = new HashMap<>();
        sportsMap.put(1,"篮球");
        sportsMap.put(2,"篮球");
        sportsMap.put(3,"足球");
        sportsMap.put(4,"篮球");
        sportsMap.put(5,"篮球");
        return sportsMap;
    }

    @GetMapping("/register")
    public String registerForm(Model model) {
        return "registerForm";
    }

    @PostMapping("/register")
    public String registerResult(@ModelAttribute("user") Register register, Model model) {
//        if (register.isAgree()){
//            model.addAttribute("errMsg","必须同意服务协议才可注册");
//            return "registerForm";
//        }
        return "registerResult";
    }

}
